Page({

    // 请求生成名片接口
    generateBusinessCards(card) {
        console.log("生成名片请求开始");
        const requestData = {
            avatar: this.data.card.avatar,
            name: this.data.card.name,
            position: this.data.card.position,
            company: this.data.card.company,
            phone: this.data.card.phone,
            email: this.data.card.email,
            address: this.data.card.address
        };

        wx.request({
            url: 'http://localhost:8080/system/draw-card/generate', // 替换为你的后端接口地址
            method: 'POST',
            data: requestData,
            header: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${wx.getStorageSync('token')}` // 如果需要带 Token
            },
            success: (res) => {
                console.log("名片生成成功", res.data);
                if (res.statusCode === 200 && res.data.message === "名片生成成功") {
                    // 获取生成的名片图片路径
                    this.setData({
                        hasCreatedCard: true,
                        cardImagePaths: res.data.fileName, // 获取名片图片路径
                    });
                } else {
                    // 接口返回错误信息
                    console.error('名片生成失败:', res.data.message);
                    wx.showToast({
                        title: '名片生成失败',
                        icon: 'none',
                    });
                }
            },
            fail: (err) => {
                // 请求失败
                console.error('请求失败:', err);
                wx.showToast({
                    title: '请求失败，请稍后再试',
                    icon: 'none',
                });
            }
        });
    },


})